package com.jsy.common.leetcode;

import java.util.HashSet;
import java.util.Random;

class RandomizedSet {

    private static HashSet<Integer> set;

    public RandomizedSet() {
        set = new HashSet<>();
    }
    
    public boolean insert(int val) {
       return set.add(val);
    }
    
    public boolean remove(int val) {
        return set.remove(val);
    }
    
    public int getRandom() {
        Random random = new Random();
        int randomInt = random.nextInt(set.size());
        System.out.println(randomInt);

        int count = 0;
        for (Integer integer : set) {
            if (count == randomInt){
                return integer;
            }
            count++;
        }
        return 0;
    }

    public static void main(String[] args) {
        RandomizedSet randomizedSet = new RandomizedSet();
        randomizedSet.insert(1);
        randomizedSet.insert(2);
        randomizedSet.remove(1);
        int random = randomizedSet.getRandom();
        System.out.println(random);
    }
}